package interpreter.debugger.ui;

/**
 * Continues the execution of the byte codes
 *
 * @author Kris Selbekk
 */
public class ContinueCommand extends Command {
    // Continues execution until another breakpoint is met (or until finished)
    public void exec( String[] args ) {
        if( dvm.isBreakpoint() ) dvm.clearBreakpoint();
        String bkFuncName = dvm.getFunctionName();
        dvm.exec();
        if(     dvm.isBreakpoint() &&
                dvm.getFunctionName() != null &&
                dvm.getFunctionName().equals(bkFuncName) ) {
            System.out.println( "Function: " + dvm.getFunctionName() );
            for( int i = dvm.getStartLine(); i <= dvm.getEndLine(); i++) {
                 System.out.print( String.format("%3d. %s", i, dvm.getSource(i) ));
                 if( i == dvm.getCurrentLine()) 
                     System.out.print("\t\t<---");
                 System.out.println();
            }
        }
        args = null; // Resets args
    }
    // If breakpoint is met, say where
    public void print() {
        StringBuilder out = new StringBuilder();

        // Prints notice if breakpoint was encountered.
        if( dvm.isBreakpoint() ) {
            out.append("Breakpoint encountered on line "+ dvm.getCurrentLine());
            System.out.println(out);
        }
    }
}
